# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/26 下午2:02
 @Author  : tgy
 
"""
from ListNode import ListNode


def getIntersectionNode(headA: ListNode, headB: ListNode) -> ListNode:
    ...
    if not headA or not headB:
        return None
    lastA = headA
    len_a = 1
    while lastA.next:
        len_a += 1
        lastA = lastA.next

    lastB = headB
    len_b = 1
    while lastB.next:
        len_b += 1
        lastB = lastB.next

    if lastA != lastB:
        return None

    lastA = headA
    lastB = headB

    # 让长度长的链表先走 dis
    if len_a < len_b:
        ...
        dis = len_b - len_a
        while dis:
            lastB = lastB.next
            dis -= 1
    elif len_a > len_b:
        ...
        dis = len_a - len_b
        while dis:
            lastA = lastA.next
            dis -= 1

    # 一起走
    while lastA != lastB:
        lastA = lastA.next
        lastB = lastB.next

    return lastA


if __name__ == '__main__':
    ...
